package com.atguigu.vod.controller;

import com.atguigu.commonutils.R;
import com.atguigu.vod.service.VideoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

@Api(description="阿里云视频点播微服务")
@CrossOrigin //跨域
@RestController
@RequestMapping("/eduvod/video")
public class VideoAdminController {

	@Autowired
	private VideoService videoService;

	@PostMapping("upload")
	@ApiOperation("上传视频")
	public R uploadVideo(
			@ApiParam(name = "file", value = "文件", required = true)
			@RequestParam("file") MultipartFile file) throws Exception {

		String videoId = videoService.uploadVideo(file);
		return R.ok().message("视频上传成功").data("videoId", videoId);
	}

	@DeleteMapping("{videoId}")
	public R removeVideo(@ApiParam(name = "videoId", value = "云端视频id", required = true)
						 @PathVariable String videoId){

		videoService.removeVideo(videoId);
		return R.ok().message("视频删除成功");
	}

	/**
	 * 批量删除视频
	 * @param videoIdList
	 * @return
	 */
	@DeleteMapping("delete-batch")
	public R removeVideoList(
			@ApiParam(name = "videoIdList", value = "云端视频id", required = true)
			@RequestParam("videoIdList") List<String> videoIdList){

		videoService.removeVideoList(videoIdList);
		return R.ok().message("视频删除成功");
	}
}
